package com.xcity.game.map.template;

import com.xcity.game.npc.NpcTemplate;

import naga.x.App;
import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.TemplateService;
import naga.x.game.template.annotation.Binding;
import naga.x.game.template.annotation.Excel;

/**
 * 地图资源类型
 * @author shipeng.zhu
 *
 */
@Excel(value = "map.xlsx", sheetName = "地图资源类型")
public class MineTypeTemplate extends Template {

	/** 矿名 */
	protected String name;

	/** 图标资源 */
	protected String img;
	
	/** 动画资源 */
	protected String anim;

	/** 消耗体力 */
	protected int costStr;

	/** 消耗钻石 */
	protected int costStone;

	/** 每5分钟产金 */
	protected int produceGold;

	/** 每5分钟产道具1 */
	protected int[] produceItem;

	/** 数量 */
	protected int[] produceItemCount;

	/** npcid */
	protected int[] npcIds;
	
	/** bossid */
	protected int bossId;
	
	
	protected NpcTemplate[] npcs;
	protected NpcTemplate boss;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}
	
	public String getAnim() {
		return anim;
	}

	public void setAnim(String anim) {
		this.anim = anim;
	}

	public int getCostStr() {
		return costStr;
	}

	public void setCostStr(int costStr) {
		this.costStr = costStr;
	}

	public int getCostStone() {
		return costStone;
	}

	public void setCostStone(int costStone) {
		this.costStone = costStone;
	}

	public int getProduceGold() {
		return produceGold;
	}

	public void setProduceGold(int produceGold) {
		this.produceGold = produceGold;
	}

	public int[] getProduceItem() {
		return produceItem;
	}

	public void setProduceItem(int[] produceItem) {
		this.produceItem = produceItem;
	}

	public int[] getProduceItemCount() {
		return produceItemCount;
	}

	public void setProduceItemCount(int[] produceItemCount) {
		this.produceItemCount = produceItemCount;
	}

	public int[] getNpcIds() {
		return npcIds;
	}

	public void setNpcIds(int[] npcIds) {
		this.npcIds = npcIds;
	}

	public int getBossId() {
		return bossId;
	}

	public void setBossId(int bossId) {
		this.bossId = bossId;
	}
	
	public NpcTemplate getBoss(){
		return boss = App.getApp().getServiceManager().get(TemplateService.class).get(NpcTemplate.class, bossId);
	}

	public NpcTemplate[] getNpcs(){
		if(npcs == null && npcIds != null){
			npcs = new NpcTemplate[npcIds.length];
			TemplateService service = App.getApp().getServiceManager().get(TemplateService.class);
			for(int i = 0; i < npcIds.length; i++){
				NpcTemplate npc = service.get(NpcTemplate.class, npcIds[i]);
				npcs[i] = npc;
			}
		}
		return npcs;
	}

	@Override
	public void validate() throws TemplateException {
		if(produceItemCount == null){
			produceItemCount = new int[]{};
		}
		
		if(produceItem == null){
			produceItem = new int[]{};
		}
		if(produceItem.length != produceItemCount.length){
			throw new TemplateException("map.xlsx奖励配置错误  i=" + id);
		}
		for(int i = 0; i < produceItemCount.length; i++){
			if(produceItemCount[i] == 0){
				throw new TemplateException("map.xlsx奖励配置错误  i=" + id);
			}
		}
	}
}
